<?php
    class Dragon_Application_Resource_Log extends Zend_Application_Resource_ResourceAbstract
    {
        const DEFAULT_REGISTRY_KEY = 'Zend_Log';

        protected $_log;

        public function init ()
        {
            // Return log so bootstrap will store it in the registry
            return $this->getLogger();
        }

        public function getLogger ()
        {
            if (null === $this->_log) {
                $options = $this->getOptions();
                $path = '';
                if (array_key_exists('path', $options)) {
                    $path = $options['path'];
                    unset($options['path']);
                }

                $this->_log = new Zend_Log(new Zend_Log_Writer_Stream($path));

                $key = (isset($options['registry_key']) &&
                    !is_numeric($options['registry_key'])) ?
                        $options['registry_key'] : self::DEFAULT_REGISTRY_KEY;

                Zend_Registry::set($key, $this->_log);
            }
            return $this->_log;
        }
    }
?>